//
//  Controller.h
//  iDent
//
//  Created by Marius Corega on 3/24/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#include "Fisa.h"
#include "Manopere.h"
#include "Pacienti.h"
#include "DatatoDataView.h"
#import "FotoView.h"
#import "Poze.h"
#import "Diagnostic.h"
#import "FotoMare.h"
#import "TipFoto.h"
#import "Model3DView.h"
#import "Medic.h"

#define serverURL @"http://corega.ro/ident/nou/"


@interface Controller : NSObject {
	
	Medic* medic;
	Fisa *fisa;
	Pacienti *pacienti;
	Manopere *manopere;
	Poze *poze;
	Diagnostic *diagnostic;
	TipFoto *tipFoto;
	NSMutableArray *foto;
	NSMutableArray *fisaMA;
	
	NSMutableArray* _grupPoze;
	NSMutableArray* _pac;
	
	DatatoDataView *dataTrans;
	
	NSTimer *timer;
	NSTimer* unlockTimer;
	
	BOOL playingDirty;
	
	IBOutlet NSArrayController *fotoAC;
	IBOutlet NSArrayController *pozeAC;
	IBOutlet NSArrayController *fisaAC;
	IBOutlet NSArrayController *pacientiAC;
	IBOutlet NSArrayController *manopereAC;
	IBOutlet NSArrayController *tipFotoAC;
	IBOutlet NSArrayController *grupPozeAC;
	
	IBOutlet NSArrayController *diagnosticDC;
	
	//IBOutlet NSMutableDictionary *pacient;
	//NSMutableDictionary* intrareFisa;
	
	NSMutableString *xmlString;
	BOOL isDPLoaded, isFisaLoaded, isFotoLoaded, isRxLoaded, isDiagnosticLoaded, isTratamentLoaded, isModelLoaded;
	NSString *pozaSelectata;

	
// Foto nou
	IBOutlet NSWindow *fotoNouWindow;
	IBOutlet NSImageView *fotoNouIV;
	IBOutlet NSPopUpButton *fotoNouTipFoto;
	IBOutlet NSTextField *fotoNouDescriere;
	IBOutlet NSDatePicker *fotoNouData;
	NSURL *fotoNouURL;

//Login
	IBOutlet NSWindow *loginWindow;
	IBOutlet NSTextField *username;
	IBOutlet NSSecureTextField *password;
	
// mainWindow	
	IBOutlet NSWindow *window;
	IBOutlet NSView *contentView;
	IBOutlet NSScrollView *datePersonaleView;
	IBOutlet NSScrollView *fisaView;
	IBOutlet NSScrollView *fotoView;
	IBOutlet NSScrollView *rxView;
	IBOutlet NSScrollView *dgView;
	IBOutlet NSScrollView *modelView;
	IBOutlet NSView* searchView;

//Fotografii	
	IBOutlet NSTableView *listaFoto;
	IBOutlet FotoView *listaFotoView;
	IBOutlet FotoMare *fotoMare;
	
	IBOutlet NSTableView *listaPacienti;
	IBOutlet NSTextField *nume;
	IBOutlet NSTextField *prenume;
	IBOutlet NSTextField *cnp;
	IBOutlet NSTextField *adresa;
	IBOutlet NSTextField *telefon;
	IBOutlet NSTextField *mobil;
	IBOutlet NSTextField *email;
	IBOutlet NSTextField *cse;
	IBOutlet NSDatePicker *dataIncepere;
	IBOutlet NSDatePicker *dataTerminare;	
	IBOutlet NSSlider *zoomSlider;
	IBOutlet NSPopUpButton *grupPozePB;

//Fisa
	IBOutlet NSTableView *listaFisa;
	IBOutlet NSDatePicker *dataManopera;
	IBOutlet NSTextField *descriereManopera;
	IBOutlet NSPopUpButton *tipManopera;
	IBOutlet NSTextField *pretManopera;
	IBOutlet NSTextField *platitManopera;
	IBOutlet NSTextField *nrfacturaManopera;
	IBOutlet NSTextField *deplataManopera;
	IBOutlet NSTextView *mentiuniTV;

//FisaNou
	IBOutlet NSWindow *fisaNouWindow;
	IBOutlet NSDatePicker *dataManoperaNou;
	IBOutlet NSTextField *descriereManoperaNou;
	IBOutlet NSPopUpButton *tipManoperaNou;

	
	
	IBOutlet NSProgressIndicator *progressIndicator;
	
	IBOutlet NSTextField *debug;
}



-(NSArray*) pac;
-(void)setPac:(NSMutableArray*) p;

-(NSData*) loadServerURL: (NSString*) URL;


-(IBAction) reloadData:(id)sender;

-(IBAction) addPacient:(id)sender;
-(IBAction) updatePacient:(id)sender;
-(IBAction) stergePacient:(id) sender;

-(IBAction) updateDiagnostic:(id)sender;
-(void) loadDgForPacient:(NSString*)pacientID;


-(IBAction) addFisa:(id)sender;
-(IBAction) updateFisa:(id)sender;
-(IBAction) stergeFisa:(id)sender;
-(IBAction) updateTabelFisa:(id)sender;
-(void) loadFisaForPacient:(NSString*)pacientID;
-(void)setFisa;

-(void)loadPacienti;
- (void) loadManopere;
-(void) loadTipFoto;

-(BOOL)login;

-(IBAction) fereastraNou:(id)sender;

-(void) loadFotoForPacient:(NSString *)pacientID forceReload:(BOOL)forceReload;
-(IBAction) stergeFoto:(id) sender;
-(IBAction) updateFoto:(id)sender;
-(BOOL)arataFotocuID:(NSInteger)nr;
-(IBAction) arataGrupPoze:(id)sender;

-(NSMutableArray*) grupPoze;
-(void) setGrupPoze:(NSMutableArray*) array;

- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag;
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar;
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;

- (void)timerFireMethod:(NSTimer*)theTimer;

@end

@interface Controller (FotoNou) 

- (NSData*)generateFormData:(NSDictionary*)dict;

-(IBAction) addFoto:(id)sender;
-(IBAction) addFotoOK:(id)sender;
-(IBAction) addFotoCancel:(id)sender;
-(IBAction) openFoto:(id)sender;

@end



@interface Controller (Login) 

-(IBAction) showLogin:(id)sender;
@end

@interface  Controller (FisaNou)

-(IBAction) showFisaNou:(id)sender;
-(IBAction) adaugaFisa:(id)sender;
@end